﻿using MatlabWork.Entity;
using Newtonsoft.Json.Linq;
using OfficeOpenXml;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TestingPlatForm.MissionContrl.Entity;

namespace MatlabWork.Model
{
    public class ControlTxT
    {
        /// <summary>
        /// 读取一颗卫星数据返回
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public List<List<double>> ReadTxt(string filePath)
        {
            List<List<double>> allLists = new List<List<double>>();

            if (File.Exists(filePath))
            {
                int currentLine = 0;

                //使用 StreamReader 打开文件进行读取
                using (StreamReader sr = new StreamReader(filePath))
                {
                    string line;

                    // 跳过前三行
                    while (currentLine < 3 && sr.ReadLine() != null)
                    {
                        currentLine++;
                    }

                    // 循环读取数据
                    while ((line = sr.ReadLine()) != null && currentLine < 963) // 100 表示读取到第100行
                    {
                        // 如果当前行数是 4、12、20、28...，表示需要新建一个列表
                        if (currentLine % 8 == 3)
                        {
                            allLists.Add(new List<double>());
                        }

                        // 将当前行的数据添加到最后一个列表中

                        int lastIndex = allLists.Count - 1;

                        allLists[lastIndex].Add(double.Parse(line));

                        currentLine++;
                    }
                }

            }

            return allLists;
        }

        /// <summary>
        /// 读取多颗卫星数据
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public Dictionary<string, List<SateliteData>> ReadText(string filePath)
        {
            Dictionary<string, List<SateliteData>> keyValuePairs = new Dictionary<string, List<SateliteData>>();

            if (File.Exists(filePath))
            {
                int currentLine = 0;

                string[] lines = File.ReadAllLines(filePath);
                string[] filteredArray = lines.Where(s => !string.IsNullOrEmpty(s)).ToArray();
                int linesNumber = filteredArray.Length - 1;
                int counts = int.Parse(filteredArray[0].ToString());
                int delta = linesNumber / counts;
                int EndReturns = 1;
                for (int i = 0; i < counts; i++)
                {
                    List<SateliteData> sateliteDatas = new List<SateliteData>();
                    int startReturn = EndReturns + 2;
                    String satelite = filteredArray[EndReturns].ToString();
                    EndReturns = EndReturns + delta;
                    while (startReturn < EndReturns)
                    {
                        SateliteData sateliteData = new SateliteData();
                        if (string.IsNullOrEmpty(filteredArray[startReturn]))
                        {
                            break;
                        }
                        sateliteData.utcSecond = double.Parse(filteredArray[startReturn].ToString());
                        sateliteData.sptSecond = double.Parse(filteredArray[++startReturn].ToString());
                        sateliteData.delta_a = double.Parse(filteredArray[++startReturn].ToString());
                        sateliteData.e = double.Parse(filteredArray[++startReturn].ToString());
                        sateliteData.delta_i = double.Parse(filteredArray[++startReturn].ToString());
                        sateliteData.OMEGA0 = double.Parse(filteredArray[++startReturn].ToString());
                        sateliteData.omega = double.Parse(filteredArray[++startReturn].ToString());
                        sateliteData.M0 = double.Parse(filteredArray[++startReturn].ToString());
                        startReturn++;
                        sateliteDatas.Add(sateliteData);
                    }
                    keyValuePairs[satelite] = sateliteDatas;
                }
            }
            return keyValuePairs;
        }

        public List<BsTxData> ReadBsTx(string filePath)
        {
            List<BsTxData> bsTxDatas = new List<BsTxData>();
            if (File.Exists(filePath))
            {
                int currentLine = 0;

                string[] lines = File.ReadAllLines(filePath);
                int linesNumber = lines.Length - 4;
                int counts = int.Parse(lines[3].ToString());
                int delta = linesNumber / counts;
                int EndReturns = 4;
                for (int i = 0; i < counts; i++)
                {
                    int startReturn = EndReturns;
                    EndReturns = EndReturns + delta;
                    while (startReturn < EndReturns)
                    {
                        BsTxData bsTxData = new BsTxData();
                        bsTxData.Grid = int.Parse(lines[startReturn].ToString());
                        bsTxData.ServiceEpochUTC = int.Parse(lines[++startReturn].ToString());
                        bsTxData.ServiceDuration = int.Parse(lines[++startReturn].ToString());
                        bsTxData.Freq = int.Parse(lines[++startReturn].ToString());
                        bsTxData.Power = int.Parse(lines[++startReturn].ToString());
                        bsTxData.SatelliteSwitchUTC = lines[++startReturn].ToString();
                        bsTxData.RelaygNodeB = lines[++startReturn].ToString();
                        bsTxData.RelaySatId = lines[++startReturn].ToString();
                        startReturn++;
                        bsTxDatas.Add(bsTxData);
                    }
                }
            }

            return bsTxDatas;
        }

        public List<BsSatData> ReadBsSat(string filePath)
        {
            List<BsSatData> bsSatDatas = new List<BsSatData>();
            if (File.Exists(filePath))
            {
                int currentLine = 0;

                string[] lines = File.ReadAllLines(filePath);
                int linesNumber = lines.Length - 2;
                int counts = int.Parse(lines[1].ToString());
                int delta = linesNumber / counts;
                int EndReturns = 2;
                for (int i = 0; i < counts; i++)
                {
                    int startReturn = EndReturns;
                    EndReturns = EndReturns + delta;
                    while (startReturn < EndReturns)
                    {
                        BsSatData bsSatData = new BsSatData();
                        bsSatData.SatId = int.Parse(lines[startReturn].ToString());
                        bsSatData.SatelliteAntennal = int.Parse(lines[++startReturn].ToString());
                        bsSatData.BaseStationFeeder = int.Parse(lines[++startReturn].ToString());
                        bsSatData.FeederEpochUTC = int.Parse(lines[++startReturn].ToString());
                        bsSatData.FeederDuration = int.Parse(lines[++startReturn].ToString());
                        startReturn++;
                        bsSatDatas.Add(bsSatData);
                    }
                }
            }
            return bsSatDatas;
        }

        public Dictionary<string, List<GridBsData>> ReadGridBs(string filePath)
        {
            Dictionary<string, List<GridBsData>> keyValuePairs = new Dictionary<string, List<GridBsData>>();

            if (File.Exists(filePath))
            {
                int currentLine = 0;

                string[] lines = File.ReadAllLines(filePath);
                int linesNumber = lines.Length - 1;
                int counts = int.Parse(lines[0].ToString());
                int delta = linesNumber / counts;
                int EndReturns = 1;
                for (int i = 0; i < counts; i++)
                {
                    String satelite = lines[EndReturns].ToString();
                    int num = int.Parse(lines[++EndReturns].ToString());
                    int deltaNumber = delta - 2;
                    int deltaOmega = deltaNumber / num;
                    List<GridBsData> gridBsDatas = new List<GridBsData>();
                    int startReturn = EndReturns + 1;
                    for (int j = 0; j < num; j++)
                    {
                        EndReturns = EndReturns + deltaOmega;
                        while (startReturn < EndReturns)
                        {
                            GridBsData gridBsData = new GridBsData();
                            gridBsData.ServiceEpochUTC = int.Parse(lines[startReturn].ToString());
                            gridBsData.ServiceDuration = int.Parse(lines[++startReturn].ToString());
                            gridBsData.Cell = int.Parse(lines[++startReturn].ToString());
                            gridBsData.Cell1TAC = int.Parse(lines[++startReturn].ToString());
                            ++startReturn;
                            startReturn++;
                            gridBsDatas.Add(gridBsData);
                        }
                    }
                    EndReturns++;
                    keyValuePairs[satelite] = gridBsDatas;
                }
            }
            return keyValuePairs;
        }

        public void insertASO127(string folderPath, string FILENAME, List<TD> tDs, List<TD> deltas, int startId, int lastId)
        {
            string fileName = folderPath + "\\" + FILENAME + ".ASO";

            // 创建或打开Excel文件
            using (StreamWriter writer = new StreamWriter(fileName))
            // 如果文件不存在，则创建新的工作簿和工作表
            {
                writer.WriteLine("; Propsim Aerospace Model file, version 1.0 ");
                writer.WriteLine("[Model] ");
                writer.WriteLine("SimulationCenterFrequency = 12700000000 Hz ");
                writer.WriteLine("RFCenterFrequency = 1800000000 Hz ");
                writer.WriteLine("[LOS] ");

                int num = 0;
                for (int i = startId; i < lastId; i++)
                {
                    writer.WriteLine("A = " + num.ToString() + "," + tDs[i].number.ToString("0.000000000") + "," + deltas[i].number.ToString("0.000") + ",0");
                    num++;
                }

            }
        }

        public void insertASO472(string folderPath, string FILENAME, List<TD> tDs, List<TD> deltas, int startId, int lastId)
        {
            string fileName = folderPath + "\\" + FILENAME + ".ASO";

            // 创建或打开Excel文件
            using (StreamWriter writer = new StreamWriter(fileName))
            // 如果文件不存在，则创建新的工作簿和工作表
            {
                writer.WriteLine("; Propsim Aerospace Model file, version 1.0  ");
                writer.WriteLine("[Model] ");
                writer.WriteLine("SimulationCenterFrequency = 47200000000 Hz ");
                writer.WriteLine("RFCenterFrequency = 1800000000 Hz ");
                writer.WriteLine("[LOS] ");

                int num = 0;
                for (int i = startId; i < lastId; i++)
                {
                    writer.WriteLine("A = " + num.ToString() + "," + tDs[i].number.ToString("0.000000000") + "," + deltas[i].number.ToString("0.000") + ",0");
                    num++;
                }

            }
        }

        public void insertASO127(string folderPath, string FILENAME, List<TD> tDs, List<TD> deltas, List<downLinkData> downLinkDatas,  int startId, int lastId, double timeSpan)
        {
            string fileName = folderPath + "\\" + FILENAME + ".ASO";

            // 创建或打开Excel文件
            using (StreamWriter writer = new StreamWriter(fileName))
            // 如果文件不存在，则创建新的工作簿和工作表
            {
                writer.WriteLine("; Propsim Aerospace Model file, version 1.0 ");
                writer.WriteLine("[Model] ");
                writer.WriteLine("SimulationCenterFrequency = 12700000000 Hz ");
                writer.WriteLine("RFCenterFrequency = 1800000000 Hz ");
                writer.WriteLine("[LOS] ");
                List<downLinkData> subList = downLinkDatas.GetRange(startId, lastId - startId + 1);
                double maxVal = subList.Max(m => m.dryingRatio);
                double num = 0.00;
                for (int i = startId; i < lastId; i++)
                {
                    double dif = downLinkDatas[i].dryingRatio - maxVal;
                    writer.WriteLine("A = " + num.ToString("0.00") + "," + tDs[i].number.ToString("0.000000000") + "," + deltas[i].number.ToString("0.000") + "," + dif.ToString("0.00"));
                    num = num + timeSpan;
                    num = Math.Round(num, 2);
                }

            }
        }

        public void insertASO472(string folderPath, string FILENAME, List<TD> tDs, List<TD> deltas, List<UpLinkData> upLinkDatas, int startId, int lastId, double timeSpan)
        {
            string fileName = folderPath + "\\" + FILENAME + ".ASO";

            // 创建或打开Excel文件
            using (StreamWriter writer = new StreamWriter(fileName))
            // 如果文件不存在，则创建新的工作簿和工作表
            {
                writer.WriteLine("; Propsim Aerospace Model file, version 1.0  ");
                writer.WriteLine("[Model] ");
                writer.WriteLine("SimulationCenterFrequency = 47200000000 Hz ");
                writer.WriteLine("RFCenterFrequency = 1800000000 Hz ");
                writer.WriteLine("[LOS] ");
                List<UpLinkData> subList = upLinkDatas.GetRange(startId, lastId - startId + 1);
                double maxVal = subList.Max(m => m.dryRatio);

                double num = 0.00;
                for (int i = startId; i < lastId; i++)
                {
                    double dif = upLinkDatas[i].dryRatio - maxVal;
                    writer.WriteLine("A = " + num.ToString("0.00") + "," + tDs[i].number.ToString("0.000000000") + "," + deltas[i].number.ToString("0.000") + "," + dif.ToString("0.00"));
                    num += timeSpan;
                    num = Math.Round(num, 2);

                }

            }
        }


        public void insertASO(string folderPath, string FILENAME, List<TD> tDs, List<TD> deltas, int startId, int lastId)
        {
            string fileName = folderPath + "\\" + FILENAME + ".ASO";

            // 创建或打开Excel文件
            using (StreamWriter writer = new StreamWriter(fileName))
            // 如果文件不存在，则创建新的工作簿和工作表
            {
                writer.WriteLine("; Propsim Aerospace Model file, version 1.0  ");
                writer.WriteLine("[Model] ");
                writer.WriteLine("SimulationCenterFrequency = 18000000000 Hz ");
                writer.WriteLine("RFCenterFrequency = 1800000000 Hz ");
                writer.WriteLine("[LOS] ");

                int num = 0;
                for (int i = startId; i < lastId; i++)
                {
                    writer.WriteLine("A = " + num.ToString() + "," + tDs[i].number.ToString("0.000000000") + "," + deltas[i].number.ToString("0.000") + ",0");
                    num++;
                }

            }
        }

        public void insertASO127(string folderPath, string FILENAME, List<TD> tDs, List<TD> deltas)
        {
            string fileName = folderPath + "\\" + FILENAME + ".ASO";

            // 创建或打开Excel文件
            using (StreamWriter writer = new StreamWriter(fileName))
            // 如果文件不存在，则创建新的工作簿和工作表
            {
                writer.WriteLine("; Propsim Aerospace Model file, version 1.0 ");
                writer.WriteLine("[Model] ");
                writer.WriteLine("SimulationCenterFrequency = 12700000000 Hz ");
                writer.WriteLine("RFCenterFrequency = 1800000000 Hz ");
                writer.WriteLine("[LOS] ");

                for (int i = 0; i < tDs.Count; i++)
                {
                    writer.WriteLine("A = " + i.ToString() + "," + tDs[i].number.ToString("0.000000000") + "," + deltas[i].number.ToString("0.000") + ",0");
                }

            }
        }

        public void insertASO472(string folderPath, string FILENAME, List<TD> tDs, List<TD> deltas)
        {
            string fileName = folderPath + "\\" + FILENAME + ".ASO";

            // 创建或打开Excel文件
            using (StreamWriter writer = new StreamWriter(fileName))
            // 如果文件不存在，则创建新的工作簿和工作表
            {
                writer.WriteLine("; Propsim Aerospace Model file, version 1.0  ");
                writer.WriteLine("[Model] ");
                writer.WriteLine("SimulationCenterFrequency = 47200000000 Hz ");
                writer.WriteLine("RFCenterFrequency = 1800000000 Hz ");
                writer.WriteLine("[LOS] ");

                for (int i = 0; i < tDs.Count; i++)
                {
                    writer.WriteLine("A = " + i.ToString() + "," + tDs[i].number.ToString("0.000000000") + "," + deltas[i].number.ToString("0.000") + ",0");
                }

            }
        }

        public void insertASO(string folderPath, string FILENAME, List<TD> tDs, List<TD> deltas)
        {
            string fileName = folderPath + "\\" + FILENAME + ".ASO";

            // 创建或打开Excel文件
            using (StreamWriter writer = new StreamWriter(fileName))
            // 如果文件不存在，则创建新的工作簿和工作表
            {
                writer.WriteLine("; Propsim Aerospace Model file, version 1.0  ");
                writer.WriteLine("[Model] ");
                writer.WriteLine("SimulationCenterFrequency = 18000000000 Hz ");
                writer.WriteLine("RFCenterFrequency = 1800000000 Hz ");
                writer.WriteLine("[LOS] ");

                for (int i = 0; i < tDs.Count; i++)
                {
                    writer.WriteLine("A = " + i.ToString() + "," + tDs[i].number.ToString("0.000000000") + "," + deltas[i].number.ToString("0.000") + ",0");
                }

            }
        }

        public void insertASOPre(string folderPath, string FILENAME, List<TD> tDs, List<TD> deltas, int startId, int lastId, int centerTime, int centerNumber)
        {
            string fileName = folderPath + "\\" + FILENAME + ".ASO";

            // 创建或打开Excel文件
            using (StreamWriter writer = new StreamWriter(fileName))
            // 如果文件不存在，则创建新的工作簿和工作表
            {
                writer.WriteLine("; Propsim Aerospace Model file, version 1.0  ");
                writer.WriteLine("[Model] ");
                writer.WriteLine("SimulationCenterFrequency = 18000000000 Hz ");
                writer.WriteLine("RFCenterFrequency = 1800000000 Hz ");
                writer.WriteLine("[LOS] ");

                int num = 0;
                for (int i = startId; i < lastId; i++)
                {
                    if ( num < centerTime)
                        writer.WriteLine("A = " + num.ToString() + "," + tDs[i].number.ToString("0.000000000") + "," + deltas[i].number.ToString("0.000") + "," + centerNumber);
                    else
                        writer.WriteLine("A = " + num.ToString() + "," + tDs[i].number.ToString("0.000000000") + "," + deltas[i].number.ToString("0.000") + ",0");
                    num++;
                }

            }
        }

        public void insertASOAft(string folderPath, string FILENAME, List<TD> tDs, List<TD> deltas, int startId, int lastId, int centerTime, int centerNumber)
        {
            string fileName = folderPath + "\\" + FILENAME + ".ASO";

            // 创建或打开Excel文件
            using (StreamWriter writer = new StreamWriter(fileName))
            // 如果文件不存在，则创建新的工作簿和工作表
            {
                writer.WriteLine("; Propsim Aerospace Model file, version 1.0  ");
                writer.WriteLine("[Model] ");
                writer.WriteLine("SimulationCenterFrequency = 18000000000 Hz ");
                writer.WriteLine("RFCenterFrequency = 1800000000 Hz ");
                writer.WriteLine("[LOS] ");

                int num = 0;
                for (int i = startId; i < lastId; i++)
                {
                    if (num == centerTime || num > centerTime)
                        writer.WriteLine("A = " + num.ToString() + "," + tDs[i].number.ToString("0.000000000") + "," + deltas[i].number.ToString("0.000") + "," + centerNumber);
                    else
                        writer.WriteLine("A = " + num.ToString() + "," + tDs[i].number.ToString("0.000000000") + "," + deltas[i].number.ToString("0.000") + ",0");
                    num++;
                }

            }
        }

        public void insertUni(string folderPath, string FILENAME, List<location> locations, double x, double y, double z)
        {
            string fileName = folderPath + "\\" + FILENAME + ".uni";

            // 创建或打开Excel文件
            using (StreamWriter writer = new StreamWriter(fileName))
            // 如果文件不存在，则创建新的工作簿和工作表
            {
                int num = 0;
                for (int i = 0; i < 240; i++)
                {
                    int NUM = num;
                    writer.WriteLine(NUM.ToString() + " " + locations[0].x_st.ToString("0.000000") + " " + locations[0].y_st.ToString("0.000000") + " " + locations[0].z_st.ToString("0.000000") + " 0 0 0 ");
                    num++;
                }

                for (int i = 0; i < locations.Count; i++)
                {
                    int NUM = num;
                    writer.WriteLine(NUM.ToString() + " " + locations[i].x_st.ToString("0.000000") + " " + locations[i].y_st.ToString("0.000000") + " " + locations[i].z_st.ToString("0.000000") + " " + x.ToString("0.000000") + " " + y.ToString("0.000000") + " " + z.ToString("0.000000"));
                    num++;
                }
                for (int i = 0; i < 240; i++)
                {
                    int NUM = num;
                    writer.WriteLine(NUM.ToString() + " " + locations[locations.Count - 1].x_st.ToString("0.000000") + " " + locations[locations.Count - 1].y_st.ToString("0.000000") + " " + locations[locations.Count - 1].z_st.ToString("0.000000") + " 0 0 0 ");
                    num++;
                }

            }
        }


        public void insertUni(string folderPath, string FILENAME, List<numTest> numTests)
        {
            string fileName = folderPath + "\\" + FILENAME + ".uni";

            // 创建或打开Excel文件
            using (StreamWriter writer = new StreamWriter(fileName))
            // 如果文件不存在，则创建新的工作簿和工作表
            {
                int num = 1;
                for (int i = 0; i < numTests.Count; i++)
                {
                    int NUM = i ;
                    writer.WriteLine(NUM.ToString() + " " + numTests[0].x.ToString("0.000000") + " " + numTests[0].y.ToString("0.000000") + " " + numTests[0].z.ToString("0.000000") + " " + numTests[0].vx.ToString("0.000000") + " " + numTests[0].vy.ToString("0.000000") + " " + numTests[0].vz.ToString("0.000000"));
                    num++;
                }
            }
        }

        public void insertUni(string folderPath, string FILENAME, List<numTest> numTests, int startId, int lastId)
        {
            string fileName = folderPath + "\\" + FILENAME + ".uni";

            // 创建或打开Excel文件
            using (StreamWriter writer = new StreamWriter(fileName))
            // 如果文件不存在，则创建新的工作簿和工作表
            {
                int num = 1;
                for (int i = startId; i < lastId; i++)
                {
                    int NUM = num ;
                    writer.WriteLine(NUM.ToString() + " " + numTests[i].x.ToString("0.000000") + " " + numTests[i].y.ToString("0.000000") + " " + numTests[i].z.ToString("0.000000") + " " + numTests[i].vx.ToString("0.000000") + " " + numTests[i].vy.ToString("0.000000") + " " + numTests[i].vz.ToString("0.000000"));
                    num++;
                }
            }
        }

        public void insertUni(string folderPath, string FILENAME, List<location> locations)
        {
            string fileName = folderPath + "\\" + FILENAME + ".uni";

            // 创建或打开Excel文件
            using (StreamWriter writer = new StreamWriter(fileName))
            // 如果文件不存在，则创建新的工作簿和工作表
            {
                int num = 0;
                for (int i = 0; i < 240; i++)
                {
                    int NUM = num;
                    writer.WriteLine(NUM.ToString() + " " + locations[0].x_st.ToString("0.000000") + " " + locations[0].y_st.ToString("0.000000") + " " + locations[0].z_st.ToString("0.000000") + " 0 0 0 ");
                    num++;
                }

                for (int i = 0; i < locations.Count; i++)
                {
                    int NUM = num;
                    writer.WriteLine(NUM.ToString() + " " + locations[i].x_st.ToString("0.000000") + " " + locations[i].y_st.ToString("0.000000") + " " + locations[i].z_st.ToString("0.000000") + " 0 0 0 " );
                    num++;
                }
                for (int i = 0; i < 240; i++)
                {
                    int NUM = num;
                    writer.WriteLine(NUM.ToString() + " " + locations[locations.Count -1].x_st.ToString("0.000000") + " " + locations[locations.Count -1].y_st.ToString("0.000000") + " " + locations[locations.Count - 1].z_st.ToString("0.000000") + " 0 0 0 ");
                    num++;
                }

            }
        }

        public void insertTXT(Dictionary<string, List<SateliteData>> SateliteDataDic, string FILENAME)
        {
            string currentDirectory = Directory.GetCurrentDirectory();
            string directiory = currentDirectory + "\\outPut";
            string fileName = directiory + "\\" + FILENAME + ".txt";

            // 创建或打开Excel文件
            using (StreamWriter writer = new StreamWriter(fileName))
            // 如果文件不存在，则创建新的工作簿和工作表
            {
                writer.WriteLine(SateliteDataDic.Count());
                foreach (var item in SateliteDataDic)
                {
                    writer.WriteLine(item.Key);
                    writer.WriteLine(item.Value.Count);
                    foreach (var value in item.Value)
                    {
                        writer.WriteLine(value.utcSecond);
                        writer.WriteLine(value.sptSecond);
                        writer.WriteLine(value.delta_a.ToString("0.00000e+00"));
                        writer.WriteLine(value.e);
                        writer.WriteLine(value.delta_i);
                        writer.WriteLine(value.OMEGA0);
                        writer.WriteLine(value.omega);
                        writer.WriteLine(value.M0);                       
                    }
                }

            }
        }

        public void insertTXT(List<AlmanacInfo> data, string FILENAME) 
        {
            string currentDirectory = Directory.GetCurrentDirectory();
            string directiory = currentDirectory + "\\outPut";
            string fileName = directiory + "\\" + FILENAME + ".TXT";

            // 创建或打开Excel文件
            using (StreamWriter writer = new StreamWriter(fileName))
            // 如果文件不存在，则创建新的工作簿和工作表
            {
               writer.WriteLine(data.Count);
                foreach (var item in data) 
                {
                    writer.WriteLine(item.scId);
                    writer.WriteLine(item.infos.Count);
                    foreach (var info in item.infos) 
                    {
                        writer.WriteLine(info.accSecond);
                        writer.WriteLine(info.deltA);
                        writer.WriteLine(info.ecc);
                        writer.WriteLine(info.inc);
                        writer.WriteLine(info.raan);
                        writer.WriteLine(info.draan);
                        writer.WriteLine(info.aop);
                        writer.WriteLine(info.meanAnomaly);
                    }
                }
            }
        }

        public void insertTXT( List<EphData> ephDatas, string FILENAME)
        {
            string currentDirectory = Directory.GetCurrentDirectory();
            string directiory = currentDirectory + "\\outPut";
            string fileName = directiory + "\\" + FILENAME + ".txt";

            // 创建或打开Excel文件
            using (StreamWriter writer = new StreamWriter(fileName))
            // 如果文件不存在，则创建新的工作簿和工作表
            {
                foreach (var item in ephDatas)
                {
                    writer.WriteLine(item.instantTime.Year + " " +item.instantTime.Month.ToString("D2") + " " + item.instantTime.Day.ToString("D2") + " " +
                        item.instantTime.Hour.ToString("D2") + " " +item.instantTime.Minute.ToString("D2") + " " + item.instantTime.Second.ToString("D2") + " " +
                        item.j2000X + " " +item.j2000Y + " " + item.j2000Z + " " +
                        item.j2000Vx + " " +item.j2000Vy + " " + item.j2000Vz 
                        );
                }

            }
        }

        public void insertTXT(List<downLinkData> downLinkDatas, List<UpLinkData> upLinkDatas, string folderPath, int index, int endIndex)
        {
            string directiory = folderPath;
            string fileName = directiory + "\\前向链路信干燥比.txt";

            // 创建或打开Excel文件
            using (StreamWriter writer = new StreamWriter(fileName))
            // 如果文件不存在，则创建新的工作簿和工作表
            {
                for (int i = index; i < endIndex; i++)
                {
                    writer.WriteLine(downLinkDatas[i].dryingRatio);
                }

            }
            fileName = directiory + "\\反向链路信干燥比.txt";
            using (StreamWriter writer = new StreamWriter(fileName))
            // 如果文件不存在，则创建新的工作簿和工作表
            {
                for (int i = index; i < endIndex; i++)
                {
                    writer.WriteLine(upLinkDatas[i].dryRatio);
                }

            }
        }

    }
}
